[Back]
MacOS X Developer Preview Release Notes Copyright ©2000
by Apple Computer, Inc. All Rights Reserved.
Mac OS X Developer Preview Release Notes:
Compiler
These notes are for the Mac OS X Developer Preview release of the compiler.
Although some components of this compiler are based on the GNU C compiler,
version 2.7.2.1 or 2.6.3, the compiler proper is based on gcc version 2.95.2,
which provides much-improved support for C++ compared to previous gcc-
and egcs-based compilers. It compiles programs written in C, C++, or Objective-C.
An Objective-C++ compiler is not available at this time.
Notes Specific to Mac OS X
New Features
The following new features have been added to the compiler since Mac OS
X Server release 1.1.
Improved Template Support
Member templates are now supported. The Standard Template Library is
much closer to standard mandated requirements. For example, in this release,
STL's memory allocation is based on the standard mandated Allocate template
and not the alloc template the previous STLs used.
Thread Safety
Exceptions in a multithreaded program and crossing shared library boundaries
now work. The runtime calls set_terminate(), set_unexpected(),
and set_newhandler() now work on a per thread basis. Each thread
now has its own terminate and unexpected exception handler and its own
new handler.
Exception Handling in C++
Previously, in order to make use of exception handling features, the -fhandle-exceptions
switch had to be used. This switch is now obsolete since these features
are now enabled by default. To disable these features, the -fno-exceptions
switch can be used, though this switch does not guarantee absence of overhead
due to features related to exception handling.
AltiVec Support
This compiler includes preliminary AltiVec
(Velocity Engine) support for G4-class CPUs. To compile AltiVec code, use
the -faltivec switch to turn on the compiler's vector operation support.
The compiler assumes and keeps 16-byte stack alignment. Assembly code
which calls compiler-generated functions should also respect this alignment.
Motorola's AltiVec
Programming Interface and Environments manuals, which describe
how to write AltiVec code, are available as PDF files.
Undocumented Features
Although they are not new, the following features are not documented elsewhere:
Pragmas for m68K Alignment
All compilers now understand the following pragmas:
-
#pragma options align=alignment
-
Where alignment is either mac68K, power, or reset.
-
#pragma pack(n)
-
Where n is an optional whole number.
These pragmas affect how fields are aligned within structures. Normally,
fields are aligned on natural boundaries in such a way that 32-bit (and
larger) quantities are 4-byte aligned. However, when you use the options
align or pack(2) pragmas, fields whose size is at least 16
bits are aligned on even addresses.
Pascal Strings
The cc command line flag -fpascal-strings enables the compiler
to recognize Pascal strings. A Pascal string is a string containing an
initial "\p". During compilation, the string's initial "\p" will be replaced
with a byte containing the length of the string (not including the "\p").
The type of such a string is unsigned char *. It is an
error for any pascal string to be longer than 255 characters. When a "\p"
is seen in a string and the -fpascal-strings flag is not given,
the compiler will issue a diagnostic (a warning in C, an error in C++)
about an unknown escape sequence.
c++ command
The c++ command can be used to compile C++ source code. This command,
in turn, invokes the cc command. Some third party software looks
for this command during the build process.
Header File Directories
The preprocessor now searches the directory /usr/local/include by default
as a last resort when it is looking for header files.
The -Wmost Compiler Flag
The -Wmost compiler flag is equivalent to the Free Software Foundation's
-Wall, except that it doesn't turn on -Wparenthesis. The
-Wmost flag also suppresses warning messages about static constants
that are not actually used. This flag is for internal use, and its definition
may change in a future release.
Please ignore the documentation on the -Wmost flag in the section
Options to Request or Suppress Warnings of the compiler manual.
Frameworks
You can now specify frameworks on the linker and preprocessor command lines.
The -F flag is accepted by both the linker and the preprocessor,
while the -framework flag is accepted by the linker only. The -framework
flag is documented in the section Options for Linking of the compiler
manual, and the -F flag is defined as follows:
-
-F directory
-
This option adds the specified directory to the head of the list of directories
to be searched for frameworks. If you use more than one -F option,
the directories are scanned in left-to-right order; the standard framework
directories (/Local/Library/Frameworks, followed by /System/Library/Frameworks)
are searched last.
In your Objective-C code, include framework headers using the following
format:
#include <framework/include_file.h>
Where framework is the name of the framework (such as AppKit or
Foundation; don't include the extension) and include_file.h is the
name of the header file to be included.
Please ignore the documentation on the -framework flag in the
section Options Controlling the Preprocessor of the compiler manual.
Recognized C++ File Extensions
If the name of your source file ends in .cc, .cxx, .cp,
.cpp, or .C, gcc attempts to compile your program
with the C++ compiler.
Macros
-
In new code, use the __APPLE_CPP__ macro instead of the __NEXT_CPP__ macro.
(The __APPLE_CPP__ macro is predefined only when using Apple's preprocessor,
rather than the gcc-derived one. The former is capable of creating and
using precompiled header files when processing C and Objective C source
code.)
-
There are two relatively new macros: __APPLE__ and __APPLE_CC__.The former
refers to any Apple platform, though at present it is only predefined in
Apple's gcc-based Mac OS X and Mac OS X Server compilers. The value of
the latter is an integer that corresponds to the version number of the
compiler. This should allow one to distinguish, for example, between compilers
based on the same version of gcc, but with different bug fixes or features.
At present, larger values denote (chronologically) later compilers.
-
Avoid using the following macros, since they either are no longer predefined,
or will not be predefined in future releases (suggestions for replacements
appear inside parentheses):
-
NATURAL_ALIGNMENT (use the __NATURAL_ALIGNMENT__ macro instead)
-
__NATURAL_ALIGNMENT (use the __NATURAL_ALIGNMENT__ macro instead)
-
__ARCHITECTURE__ (use a target-specific macro such as __i386__ or __ppc__)
-
ppc (use the __ppc__ macro instead)
-
__ppc (use the __ppc__ macro instead)
-
unix (use the __APPLE__ macro instead)
-
__unix (use the __APPLE__ macro instead)
-
__unix__ (use the __APPLE__ macro instead)
Debugging Features
The compiler includes two new options to assist in debugging. Specify the
-H flag on the command to have the compiler emit a listing of included
header files (indented to reflect where they are included). Specify the
-dM option after the -E (preprocess) option to get a listing
of all macros along with their full definitions.
Using the R2 Register
Although currently the compiler does not use the r2 register for any purpose
whatsoever, future versions of the compiler may begin to treat this register
as a volatile register. Therefore, (inline) assembly language code must
not depend on the value of this register being preserved across function
calls.
Known Problems and Issues
Commonly implemented extensions
This compiler does not support several common extensions other Macintosh
compilers support. These include certain pragmas, such as once,
unused, import, and export. In addition, in
some areas, this compiler adheres more strictly to the C++ Standard than
some other compilers, resulting in this compiler rejecting some source
code that other compilers might accept. The -fpermissive switch can often
be used to successfully compile such not-quite-C++-standard-conforming
code.
Note that the -Wno-four-char-constants switch (which is enabled by default)
may be used to prevent the compiler from issuing a warning about each occurrence
of a four-character constant (i.e., an OSType).
C++
-
The -foperator-names or -ansi switch must be used in order to make use
of the alternative representations for certain operators, such as and,
compl, not, bitand, or, etc. (See section
2.11 of the C++ Standard.)
-
If C++ code is used in a plugin or bundle, the code may not have static
or global destructors if the plugin will ever be unloaded. (This happens,
for example, when the Standard Template Library or iostreams is used.)
If the bundle is unloaded, a crash on main program exit can occur.
-
Libstdc++.a (iostreams) is not thread safe currently.
-
C style casts and functional style casts do not work when applied to function
arguments at a call site. Incorrectly, the standard argument conversions
are applied before the casts. Static cast does work correctly.
-
The Standard Template Library does not fully implement exceptions. As a
result, some functions that should throw exceptions under unusual conditions
(such as out of bounds argument values) do not. With out of bounds arguments
they might crash.
-
Wide character support is missing from the library. The standard specified
wide character routines are not implemented.
-
Using the Standard Template Library in a program forces streams to be dragged
in from the library even if streams are not otherwise used.
-
The no_throw version of the new operator will not find the new handler
specified in the set_newhandler() call.
AltiVec
Library support for vec_new(), vec_malloc(), vec_free()
, etc., as well as vector extensions to standard I/O functions such as
printf(), are not present.
Function pointers to functions returning vectors are broken.
In C++, passing an explicit const vector to certain of the
built-in vector functions can erroneously result in an error complaining
about "no instance of overloaded builtin function." A workaround for this
is to cast away the constness.
Nested Functions
Gcc extends the C language with a feature that allows one to nest function
definitions, and pass pointers to nested functions. However, this compiler
crashes when processing code that involves pointers to nested functions.
Constant Strings Should Be 7-bit Only
Unless constant strings (both char * and NSString) are 7-bit,
your code will not be portable because compilers deal with 8-bit strings
in a machine-dependent encoding.
Bugs Fixed
Line termination
The preprocessor is now able to deal with traditional Mac-OS- and Windows-style
line termination (i.e., carriage return or carriage return followed by
line feed, respectively).
Optimization-related Bugs on PowerPC
-
A hard-to-characterize class of bugs were known to cause compiler crashes.
Some of these bugs involved conversions of ints to floats.
c++ command
-
The c++ command no longer tells the compiler to link binaries with
the math library via the -lm compiler switch.
Building Shared Libraries Containing C++
In order for C++ exceptions and the typeinfo feature to work,
the compiler used to generate some runtime type information (RTTI) as variables
in .common storage. This worked fine with most normal code, but
in Mac OS X, .common storage cannot go into shared libraries.
The compiler has been changed so .common storage is no longer
used for RTTI.
Crash During Startup Inside Static Initialization
Occasionally, the compiler used to place C++ statically initialized
const variables in read-only memory. This would cause static initialization
to crash when it tried to initialize these const variables. This has now
been fixed.
Building the Compiler from Scratch
The source code for the compiler is available at the Apple
Public Source repository. This site contains instructions on how to
build the compiler from scratch. The compiler available there might be
more up to date, and may contain fixes for some of the aforementioned bugs.